package com.agile.leetcode.regix;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author:ChenZhangKun
 * @Date: 2022/3/21 16:47
 */
public class XmlRegex {
    public static void main(String[] args) {
        regex(  "             <td class=\"xl75\" x:str>公共艺术</td>","td");
    }
    public static void regex(String context,String label){
        String rgex = "<"+label+".*>(.*?)</"+label+">";
        Pattern pattern = Pattern.compile(rgex);// 匹配的模式
        Matcher m = pattern.matcher(context);
        //匹配的有多个
        List<String> list = new ArrayList<>();
        while (m.find()) {
            int i = 1;
            list.add(m.group(i));
            i++;
        }
        //只要匹配的第一个
        if(list.size()>0){
            context = list.get(0);
        }
        System.out.println(context);
    }
}
